<?php

class Application_Model_Users extends Asd_Model {
    
    public function __construct($id = null) {
        parent::__construct(new Application_Model_DbTable_Users(), $id);
    }
    
    public function authorize($login, $password) {
        $auth = Zend_Auth::getInstance();
        $authAdapter = new Zend_Auth_Adapter_DbTable(
                        $this->_dbTable->getDefaultAdapter(),
                        'users',
                        'user_login',
                        'user_password',
                        'sha1(?)'
        );
        
        $authAdapter->setIdentity($login)
                ->setCredential($password);

        $result = $auth->authenticate($authAdapter);
        if ($result->isValid()) {
            $storege = $auth->getStorage();
            $storege->write($authAdapter->getResultRowObject(null, array('password')));
            return true;
        } else {
            return false;
        }
    }
    
    public function getAllUsers(){
        return $this->_dbTable->fetchAll();
    }

    
    public function populateForm(){
        return $this->_row->toArray();
    }

}

